<?php

namespace App\Admin\Controllers\Order;

use App\Models\SwtOrderGoods;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Show;

class SwtOrderGoodController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    public function grid($order_id = "")
    {
        return Grid::make(SwtOrderGoods::with('goods') -> where('order_id', $order_id), function (Grid $grid) {
            $grid->column('goods.goods_picture','图片')->image('', 80, 80);
            $grid->column('goods_name','商品名');
            $grid->column('goods_num','数量');
            $grid->column('goods_price','售价') -> display(function($value) {
                return $value /= 100;
            });

            $grid->disableRefreshButton();
            $grid->disableFilterButton();
            $grid->disableActions();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SwtOrderGoods(), function (Show $show) {
            $show->field('id');
            $show->field('order_id');
            $show->field('goods_id');
            $show->field('goods_name');
            $show->field('goods_num');
            $show->field('goods_price');
            $show->field('goods_cost_price');
            $show->field('goods_integral');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SwtOrderGoods(), function (Form $form) {
            $form->display('id');
            $form->text('order_id');
            $form->text('goods_id');
            $form->text('goods_name');
            $form->text('goods_num');
            $form->text('goods_price');
            $form->text('goods_cost_price');
            $form->text('goods_integral');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
